package com.info33.platform.system.controller;

import com.info33.platform.business.app.dto.AppUpdateDTO;
import com.info33.platform.business.app.vo.AppCenterVO;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.system.dto.SysUserProfileDTO;
import com.info33.platform.system.entity.SysUserProfile;
import com.info33.platform.system.service.SysUserProfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysUserProfile")
@Api(tags = "系统 - 用户 - 资料")
public class SysUserProfileController extends BaseController<SysUserProfileService, SysUserProfile> {

    private final SysUserProfileService sysUserProfileService;

    @Autowired
    public SysUserProfileController(SysUserProfileService sysUserProfileService) {
        super(sysUserProfileService);
        this.sysUserProfileService = sysUserProfileService;
    }

    @PutMapping(value = "/pc/changeHeadImg")
    @ApiOperation(value = "pc 修改头像", notes = "id、headImg")
    public Result<Object> pcChangeHeadImg(
            @RequestBody SysUserProfileDTO dto) {
        return sysUserProfileService.pcChangeHeadImg(dto);
    }

    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * app 用户认证相关操作
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */

    @GetMapping(value = "/check/certification")
    public Result<Object> checkCertification() {
        return sysUserProfileService.checkCertification(getCurrentUser());
    }

    @PostMapping(value = "/app/certification")
    @ApiOperation(value = "app - 认证", notes = "仅传身份证正反面图片")
    public Result<Object> appCertification(@RequestParam(value = "file") MultipartFile[] multipartFiles) {
        if (ObjectUtils.isEmpty(multipartFiles) || multipartFiles.length < 2) {
            return Result.error("请先上传资源");
        }
        return sysUserProfileService.appCertification(getCurrentUser(), multipartFiles);
    }

    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * app
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */

    @GetMapping(value = "/app/profile/echo")
    @ApiOperation(value = "app - 个人拓展信息回显", notes = "我的-编辑资料：基本信息 + 拓展信息 + 教育经历")
    public Result<AppCenterVO> appProfileEcho() {
        return Result.ok(sysUserProfileService.appProfileEcho(getCurrentUser()));
    }

    @PutMapping(value = "/app/update")
    @ApiOperation(value = "app - 更新用户信息", notes = "我的-编辑资料：基本信息 + 拓展信息 + 教育经历")
    public Result<Object> appUpdate(
            @Validated(value = {AppUpdateDTO.AppUpdate.class}) @RequestBody AppUpdateDTO dto) {
        return sysUserProfileService.appUpdate(dto, getCurrentUser());
    }

}